#include <QCoreApplication>  
#include <QSqlDatabase>  
#include <QSqlQuery>  
#include <QDebug>  

int main(int argc, char *argv[]) {  
    QCoreApplication app(argc, argv);  

    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");  
    db.setDatabaseName("test.db");  
    if (!db.open()) {  
        qDebug() << "Database open failed!";  
        return 1;  
    }  

    QSqlQuery query("SELECT * FROM person");  
    while (query.next()) {  
        // 显式转换为 int 和 QString  
        qDebug() << "ID:" << query.value(0).toInt() << "Name:" << query.value(1).toString();  
    }  

    return app.exec();  
}  
